using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;


namespace BUSLayer
{
    class Database
    {
        //#region
        public static OleDbConnection ConnectionData()
        {

            //B1: tao chuoi cnStr
            string cnStr;
            cnStr = "Provider = Microsoft.Jet.OLEDB.4.0;";
            cnStr = cnStr + @"Data Source = QLSoTietKiem.mdb";
            //B2: mo ket noi CSDL
            OleDbConnection cn = new OleDbConnection(cnStr);
            cn.Open();
            return cn;
        }
        // #endregion
        // #region
        public static long ExecuteScalar(string sql)
        {
            try
            {
                //B1&B2 tao chuoi kiet noi
                OleDbConnection cn;
                cn = Database.ConnectionData();
                //B3 Tao chuoi ket noi CSDL
                // string sql = "SELECT  Max(MaLoaiTietKiem) From LOAITIETKIEM";
                //B4 thuc thi chuoi sql
                OleDbCommand cmd = new OleDbCommand(sql, cn);
                long kq;
                kq = long.Parse(cmd.ExecuteScalar().ToString());
                cn.Close();
                return kq;
            }
            catch
            {
                return 0;
            }

        }

        //#endregion
    }
}
